<!--
 * @Author: wangding
 * @Date: 2020-11-02 11:34:52
 * @LastEditTime: 2021-01-26 16:51:00
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \solaxcloud\src\views\system\pushNews\add.vue
-->
<template>
    <div>
        <el-dialog
            :title="$t('add')"
            :visible="newVisible"
            width="600px"
            @close="()=>{$store.commit('setNewVisible',false)}">
            <el-form ref="form" :model="form" label-width="160px" >
                <el-row :gutter="20">
                    <el-col :span="18" :offset="2">
                        <el-form-item :label="$t('pushNews.title')" prop="title" :rules="[{ required: true, message: $t('index_js_notNull')}]">
                            <el-input v-model="form.title" :placeholder="$t('pleaseInput')"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="20">
                    <el-col :span="18" :offset="2">
                        <el-form-item :label="$t('pushNews.contents')" prop="contents" :rules="[{ required: true, message: $t('index_js_notNull')}]">
                            <el-input type="textarea" v-model="form.contents" :placeholder="$t('pleaseInput')"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="20">
                    <el-col :span="18" :offset="2">
                        <el-form-item :label="$t('pushNews.web.url')" prop="domain" :rules="[{ required: true, message: $t('index_js_notNull')}]">
                            <el-input type="text" v-model="form.domain" :placeholder="$t('pleaseInput')"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="20">
                    <el-col :span="18" :offset="2">
                        <el-form-item >
                            <p style="color:red;">不同的域以英文","逗号分割</p>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="()=>{$store.commit('setNewVisible',false)}">{{$t('cancel')}}</el-button>
                <el-button type="primary" @click="save('form')">{{$t('sure')}}</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
export default {
    components: {

    },
    props: {

    },
    data() {
        return {
            form:{
                title:'',
                contents:'',
                domain:''
            },
            editRows:{}
        };
    },
    computed: {
        newVisible(){
            return this.$store.state.sysStore.newVisible
        }
    },
    watch: {

    },
    created() {

    },
    mounted() {

    },
    methods: {
        async pushnewsAddNews(){
            let res = await this.API.pushnewsAddNews(Object.assign({},this.form,{isPush:0}))
            if(res.success){
                this.$message({
                message: this.$t('index.control_success'),
                type: 'success'
                });
                this.$store.commit('setNewVisible',false)
                this.$emit('uploadData',true)
            }else{
                this.$message({
                message: this.$t('index.control_fail'),
                type: 'warning'
                });
            }
        },
        save(formName){
            this.$refs[formName].validate((valid) => {
              if (valid) {
                  this.pushnewsAddNews()
              } else {
                console.log('error submit!!');
                return false;
              }
            });
        },
       
    },
};
</script>

<style  lang="less" scoped>

</style>
